import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import CategoryList from '@/views/CategoryList'
import CategoryEdit from '@/views/CategoryEdit'
import ItemList from '@/views/ItemList'
import ItemEdit from '@/views/ItemEdit'
import HeroList from '@/views/HeroList'
import HeroEdit from '@/views/HeroEdit'
import NewHeroList from '@/views/NewHeroList'
import NewHeroEdit from '@/views/NewHeroEdit'
import ArticleList from '@/views/ArticleList'
import ArticleEdit from '@/views/ArticleEdit'
import AdList from '@/views/AdList'
import AdEdit from '@/views/AdEdit'
import AdminUserList from '@/views/AdminUserList'
import AdminUserEdit from '@/views/AdminUserEdit'
import UserInfoList from '@/views/UserInfoList'
import UserInfoEdit from '@/views/UserInfoEdit'
import VideoList from '@/views/VideoList'
import VideoEdit from '@/views/VideoEdit'

Vue.use(VueRouter)

const routes = [
  {
    path:'/login',
    name:'login',
    meta:{
      name:'login',
      isPublic:true
    },
    component:()=>import('@/views/Login')
  },
  {
    path: '/',
    name: 'Home',
    component: Home,
    //redirect: '/categories/list',
    children:[
      {path: '/categories/list',meta:{parentTitle:'系统设置',title: "分类列表",index:"3"},component: CategoryList},
      {path: '/categories/edit/:id',meta:{parentTitle:'系统设置',title: "分类编辑",index:"3"},component: CategoryEdit,props:true},
      {path: '/categories/edit',meta:{parentTitle:'系统设置',title: "新建分类",index:"3"},component: CategoryEdit},
      
      {path: '/items/list',meta:{parentTitle:'内容管理',title: "物品列表",index:"1"},component: ItemList},
      {path: '/items/edit/:id',meta:{parentTitle:'内容管理',title: "物品编辑",index:"1"},component: ItemEdit,props:true},
      {path: '/items/edit',meta:{parentTitle:'内容管理',title: "新建物品",index:"1"},component: ItemEdit},

      {path: '/heroes/list',meta:{parentTitle:'英雄管理',title: "英雄列表",index:"1"},component: HeroList},
      {path: '/heroes/edit/:id',meta:{parentTitle:'英雄管理',title: "英雄编辑",index:"1"},component: HeroEdit,props:true},
      {path: '/heroes/edit',meta:{parentTitle:'英雄管理',title: "新建英雄",index:"1"},component: HeroEdit},

      {path: '/articles/list',meta:{parentTitle:'运营管理',title: "文章列表",index:"2"},component: ArticleList},
      {path: '/articles/edit/:id',meta:{parentTitle:'运营管理',title: "文章编辑",index:"2"},component: ArticleEdit,props:true},
      {path: '/articles/edit',meta:{parentTitle:'运营管理',title: "新建文章",index:"2"},component: ArticleEdit},

      {path: '/ads/list',meta:{parentTitle:'运营管理',title: "广告列表",index:"2"},component: AdList},
      {path: '/ads/edit/:id',meta:{parentTitle:'运营管理',title: "广告编辑",index:"2"},component: AdEdit,props:true},
      {path: '/ads/edit',meta:{parentTitle:'运营管理',title: "新建广告",index:"2"},component: AdEdit},

      {path: '/newheros/list',meta:{parentTitle:'运营管理',title: "新英雄列表",index:"2"},component: NewHeroList},
      {path: '/newheros/edit/:id',meta:{parentTitle:'运营管理',title: "新英雄编辑",index:"2"},component: NewHeroEdit,props:true},
      {path: '/newheros/edit',meta:{parentTitle:'运营管理',title: "新建英雄",index:"2"},component: NewHeroEdit},

      {path: '/admin_users/list',meta:{parentTitle:'系统设置',title: "用户列表",index:"3"},component: AdminUserList},
      {path: '/admin_users/edit/:id',meta:{parentTitle:'系统设置',title: "用户编辑",index:"3"},component: AdminUserEdit,props:true},
      {path: '/admin_users/edit',meta:{parentTitle:'系统设置',title: "新建用户",index:"3"},component: AdminUserEdit},
      
      {path: '/userinfo/list',meta:{parentTitle:'系统设置',title: "用户权限列表",index:"3"},component: UserInfoList},
      {path: '/userinfo/edit/:id',meta:{parentTitle:'系统设置',title: "用户权限编辑",index:"3"},component: UserInfoEdit,props:true},

      {path: '/videos/list',meta:{parentTitle:'内容管理',title: "视频列表",index:"1"},component: VideoList},
      {path: '/videos/edit/:id',meta:{parentTitle:'内容管理',title: "视频编辑",index:"1"},component: VideoEdit,props:true},
      {path: '/videos/edit',meta:{parentTitle:'内容管理',title: "新建视频",index:"1"},component: VideoEdit},
    ]
  },
]

const router = new VueRouter({
  routes
})
//router守卫
router.beforeEach((to,from,next)=>{
  if (!to.meta.isPublic&&!localStorage.token) {
    return next('/login')
  }
  next()
})
export default router
